#ifndef __TUYA_HAL_GPIO_H__ 
#define __TUYA_HAL_GPIO_H__


#ifdef __cplusplus
extern "C" {
#endif
#include "tuya_cloud_types.h"
#include "tal_gpio.h"
#include "tal_sw_timer.h"
  
#define TAL_LED_BLINK_FOREVER       0xFFFF  

#define KEY_SCAN_MAX_CNT            (200)

typedef enum {
    KEY_ST_RELEASE = 0,
    KEY_ST_PUSH,
}KEY_ST_T;

typedef enum {
    LED_LOW_ACTIVE = 0,
    LED_HIGH_ACTIVE = 1
}LED_ACTIVE_LEVEL_T;

typedef enum {
    LED_ST_TOGGLE = -1,
    LED_ST_OFF = 0,
    LED_ST_ON = 1
}LED_ST_T;

typedef VOID_T (*key_func_t)(UINT32_T, KEY_ST_T, UINT32_T);

typedef struct {
	UINT32_T count;
    UINT32_T on_time;
    UINT32_T off_time;
    UINT16_T blink_times;
    UINT8_T  is_start;
    LED_ST_T end_st;
    TUYA_GPIO_NUM_E led_pin_num;
    LED_ACTIVE_LEVEL_T led_active_level;
}led_operate_t;

typedef struct {
    LED_ST_T led_init_st;
    TUYA_GPIO_NUM_E led_pin_num;
    LED_ACTIVE_LEVEL_T  led_active_level;
}led_config_t;

typedef struct {
    UINT8_T key_index;
    TUYA_GPIO_NUM_E pin_num;
    TUYA_GPIO_IRQ_E pin_irq_mode;
    UINT32_T count;
    TIMER_ID* timer;
}key_operate_t;

typedef struct {
    TUYA_GPIO_NUM_E pin_num;
    TUYA_GPIO_IRQ_E pin_irq_mode;
    key_func_t      key_func
}key_config_t;

typedef struct {
    TUYA_GPIO_NUM_E pin_num;
    TUYA_GPIO_IRQ_E pin_irq_mode;
    UINT8_T channel;
}ext_key_config_t;


/**
 * @note led gpio output initialize
 * @param[in] {gpio_cfg} config information
 * @param[in] {gpio_sum} no=umbers of output gpio information
 * @return none
 */
VOID_T tal_led_gpio_init(led_config_t* gpio_cfg, UINT8_T gpio_sum);

/** 
 * @note device output(led) blink start funciton
 * @param[in] {led_pin_num} led gpio num
 * @param[in] {on_time} led on time
 * @param[in] {off_time} led off time
 * @param[in] {blink_times} blink times
 * @param[in] {end_st} end state, end with on or off
 * @return none 
 */
VOID_T tal_led_start_blink(TUYA_GPIO_NUM_E led_pin_num, UINT32_T on_time, UINT32_T off_time, UINT16_T blink_times, LED_ST_T end_st);

/**
 * @brief 
 * 
 * @param timer_id 
 * @param arg 
 * @return VOID_T 
 */
VOID_T app_led_blink_timer_cb(TIMER_ID timer_id, VOID_T *arg);

/**
 * @note device output(led) blink stop function
 * @param[in] {led_index} led id
 * @param[in] {end_st} end state, -1:toggle(only No blinking is available),0:off,1:on
 * @return none
 */
VOID_T tal_led_stop_blink(TUYA_GPIO_NUM_E led_pin_num, LED_ST_T end_st);

/**
 * @note device led is blink or not
 * @param[in] {led_index} led id
 * @return 0 is not blink, 1 is blink
 */
BOOL_T tal_led_is_blink(TUYA_GPIO_NUM_E pin_num);

/**
 * @note gpio output initialize
 * @param[in] {key_config} config information
 * @param[in] {key_sum} no=umbers of output gpio information
 * @param[in] {debounce_time} key debounce timeuser_wakeup_set
 * @param[in] {key_func} key ISR handle callback
 * @return none
 * @return none
 */
VOID_T tal_key_gpio_init(key_config_t* key_config, UINT8_T key_sum, UINT32_T debounce_time);
/**
 * @brief 
 * 
 * @param args 
 * @return VOID_T 
 */
VOID_T app_key_push_timer_cb(VOID_T *args);

/**
 * @brief 
 * 
 * @param timer_id 
 * @param arg 
 * @return VOID_T 
 */
VOID_T app_button_scan_cb(TIMER_ID timer_id, VOID_T *arg);
VOID_T app_ext_key_push_timer_cb(VOID_T *args);



#ifdef __cplusplus
}
#endif
#endif 